package com.fenghongzhang.day007animator;

import androidx.appcompat.app.AppCompatActivity;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button btn;

    private static final String TAG = "MainActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn = (Button) findViewById(R.id.btn);


    }

    public void btn(View view) {
        //第一种
        ValueAnimator valueAnimator = ValueAnimator.ofInt(btn.getWidth(), 500);
        //第二种
//        ValueAnimator valueAnimator = ValueAnimator.ofInt(btn.getLayoutParams().width, 500);

        valueAnimator.setDuration(2000);
//        valueAnimator.setRepeatMode();
//        valueAnimator.setRepeatCount();
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                Integer animatedValue = (Integer) animation.getAnimatedValue();
                Log.i(TAG, "onAnimationUpdate: "+animatedValue);

                //第一种
                btn.setWidth(animatedValue);

                //第二种
//                btn.getLayoutParams().width = animatedValue;
//                btn.requestLayout();
            }
        });

        valueAnimator.start();
    }

    public void btn1(View view) {

//        new AnimationSet();
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setDuration(2000);
        animatorSet.setInterpolator(new DecelerateInterpolator());

        ObjectAnimator animator = ObjectAnimator.ofFloat(btn, "translationX", 100, 300);
        ObjectAnimator animator1 = ObjectAnimator.ofFloat(btn, "translationY", 100, 300);

//        animatorSet.play(animator).with(animator1);
        animatorSet.playTogether(animator,animator1);

        animatorSet.start();
    }
}
